package com.neuedu.spring.mybatis.service.impl;

import com.neuedu.spring.mybatis.mapper.DeptMapper;
import com.neuedu.spring.mybatis.po.Dept;
import com.neuedu.spring.mybatis.service.IDeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 金山
 * 项目：spring-learn
 * site: https://blog.fulfill.com.cn
 * 描述
 * @data 2025/3/1313:44
 */
@Service
public class DeptServiceImpl implements IDeptService {

    @Autowired
    DeptMapper deptMapper;


    /**
     * 将ID 为 1  部门  loc  201  改成   301
     * 将ID 为 2  部门  loc  201  改成   401
     */
    @Transactional(propagation= Propagation.REQUIRED)
    @Override
    public void changeDeptLoc(int numa,int numb) {
        //ID1
        Dept dept1 = deptMapper.selectByPrimaryKey(1L);

        //将ID 为 1  部门  loc  201  改成   301
        dept1.setLoc("301");
        int updateId1Count = deptMapper.updateByPrimaryKey(dept1);

        System.out.println("中间有一些操作");

        int result = numa / numb;



        //ID5
        Dept dept5 = deptMapper.selectByPrimaryKey(5L);
        //将ID 为 2  部门  loc  201  改成   401
        dept5.setLoc("401");
        int updateId5Count = deptMapper.updateByPrimaryKey(dept5);

    }
    @Transactional(propagation= Propagation.REQUIRED)
    public void t1(){
        this.t2();
    }


    /**
     * isolation 隔离级别（幻读、脏读、不可重复读等等） DEFAULT  使用数据库的默认
     */
    @Transactional(propagation= Propagation.NEVER,isolation = Isolation.DEFAULT )
    public void t2(){

        System.out.println();
    }
}
